#ifndef _3DMATH_H
#define _3DMATH_H

#include <math.h>

class Point3
{
public:
	float	x, y, z;
	Point3(): x(0.0f), y(0.0f), z(0.0f){}
	Point3( float xx, float yy, float zz ){ x=xx; y=yy; z=zz; }
	void	set( float xx, float yy, float zz ){ x=xx; y=yy; z=zz; }
	void	add( const Point3 &point ){ x+=point.x; y+=point.y; z+=point.z; }
	void	sub( const Point3 &point ){ x-=point.x; y-=point.y; z-=point.z; }
};


class Vector3
{
public:
	float	x, y, z;
	Vector3(): x(0.0f), y(0.0f), z(0.0f){}
	Vector3( float xx, float yy, float zz ){ x=xx; y=yy; z=zz; }
	void	set( float xx, float yy, float zz ){ x=xx; y=yy; z=zz; }
	void	add( const Vector3 &vec ){ x+=vec.x; y+=vec.y; z+=vec.z; }
	void	sub( const Vector3 &vec ){ x-=vec.x; y-=vec.y; z-=vec.z; }
	void	mult( float value ){ x*=value; y*=value; z*=value; }
	float	dot( const Vector3 &src )
	{
		return x*src.x + y*src.y + z*src.z;
	}
	void	cross( const Vector3 &src, Vector3 &result )
	{
		result.x = y*src.z - z*src.y;
		result.y = z*src.x - x*src.z;
		result.z = x*src.y - y*src.x;
	}
	void	normalize()
	{
		float length = x*x+y*y+z*z;
		float frac = 1.0f/(float)sqrt(length);
		x*=frac;
		y*=frac;
		z*=frac;
	}
};


#endif